$(function(){
	// 加载表格
	searchTable = $("#searchTable").DataTable(dataTableConfig);
});
// 后面构建btn 代码
var btnModel = '    \
	{{#each func}}\
    <button type="button" class="btn btn-{{this.type}} btn-sm" onclick="{{this.fn}}">{{this.name}}</button>\
    {{/each}}';
var template = Handlebars.compile(btnModel);
var searchTable;
// 表格配置信息
var dataTableConfig = {
	"ordering": false,// 排序
	"serverSide": true,// 开启服务器模式
	"scrollX": true,// 横向滚动
	ajax: {
        "type": "POST",
        "url":'searchData4Page.action',//请求路径
        "contentType": 'application/x-www-form-urlencoded; charset=UTF-8',
        "dataType":'json',
        "data":function(d){// 查询参数
        	d.name = $('#name').val();
        	return d;
        }
	},            
	columns: [// 对应列
        {"data": "name"},
        {"data": "author"},
        {"data": "status"},
        {"data": null}
    ],
    "columnDefs": [
		{// 所有列默认值
			"targets": "_all",
			"defaultContent": ''
		},
		{
			targets: 2,
			render: function (a, b, c, d){
				if('1' == c.status)return '上映';else return '未上映';
			}
		},
       {// 最后一列添加按钮
        targets: -1,
        render: function (a, b, c, d) {
            var context =
            {
                func: [
                    {"name": "修改", "fn": "showEditPage(\'" + c.id + "\')", "type": "primary"},
                    {"name": "删除", "fn": "del(\'" + c.id + "\',\'" + c.name + "\')", "type": "danger"},
                    {"name": "查看", "fn": "search(\'" + c.id + "\')", "type": "primary"}
                ]
            };
            var html = template(context);
            return html;
        }
    }]
	,"dom": 'rt<"bottom"ip><"clear">' //生成样式
};
// 初始化页面信息
function initFrame(){
	$('#searchContent').show();
}
// 查询
function serarch(){
	searchTable.ajax.reload();
}